package com.example.rab.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.rab.entity.domain.Good;
import com.example.rab.mapper.GoodMapper;
import com.example.rab.service.GoodService;
import com.example.rab.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;


/**
 * @projectName: zzhMain
 * @package: com.example.rab.service.Impl
 * @className: GoodServiceImpl
 * @author: zzh
 * @description: TODO
 * @version: 1.0
 */
@Service
@Slf4j
public class GoodServiceImpl implements GoodService {

    @Resource
    GoodMapper goodMapper;


    @Override
    public R GoodList(Map<String, Object> map) {
        LambdaQueryWrapper<Good> userLambdaQueryWrapper = Wrappers.lambdaQuery();
        Page<Good> page = new Page<>((Integer)map.get("current") , (Integer)map.get("pageSize"),true);
        IPage<Good> IPage = goodMapper.selectPage(page , userLambdaQueryWrapper);
        IPage.setTotal(goodMapper.selectCount(userLambdaQueryWrapper));
        return R.success(IPage);
    }

    @Override
    public R GoodInsert(Good good) {
        int i=goodMapper.insert(good);
        if (i==1){
            return R.success("新增成功");
        }else {
            return R.error("新增失败");
        }
    }

}
